package top.rainf.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.rainf.service.IUserGroupService;
import top.rainf.support.Result;
import top.rainf.domain.vo.UserGroup;

import java.util.List;

/**
 * @author 星环
 * @date Wed May 10 21:04:41 CST 2023
 * @description 用户组的控制器类 由本人的生成器自动生成~
 */
@RestController
@RequestMapping("/userGroup")
public class UserGroupController {
    @Autowired
    IUserGroupService userGroupService;
    /**
    * 获取全部用户组的列表
    * @return 返回是否获取成功~
    */
    @RequestMapping("/list")
    public Result list(){
        List<UserGroup> list = userGroupService.getUserGroupList();
        if(list == null){
            return Result.fail();
        }
        return Result.success().addObj("list",list);
    }

    /**
    * 根据id获取一个用户组
    * @return 返回是否获取成功~
    */
    @RequestMapping("/one")
    public Result getOneUserGroup(int id){
        UserGroup userGroup = userGroupService.getOneById(id);
        if(userGroup == null){
                    return Result.fail();
        }
        return Result.success().addObj("data",userGroup);
    }
    /**
    * 根据id删除一个用户组
    ---------------------------
    * @param id 要删除的用户组的id
    * @return 返回是否获取成功~
    */
    @RequestMapping("/deleteById")
    public Result deleteById(int id){
        boolean suc = userGroupService.deleteOneById(id);
        return suc ? Result.success() : Result.fail();
    }

    @RequestMapping("/deleteByIds")
    public Result deleteByIds(List<Integer> idList){
        boolean suc = userGroupService.deleteAll(idList);
        return suc ? Result.success() : Result.fail();
    }

    @RequestMapping("update")
    public Result update(UserGroup userGroup){
        boolean suc = userGroupService.updateById(userGroup);
        return suc ? Result.success() : Result.fail();
    }
}
